

export class Net{
    constructor(p){
        this._parent = p
    }
    
    submit(o) {
        const data = this._checkName(o)
        // const url = $(this).attr("action")
        const url = o.action
        this.ajax(url, data)
    }

    ajax(url, data) {
        return new Promise ((res, rej) => {
            this._parent.ind.show = true
            $.ajax({
                url,
                data,
                // dataType: 'json',
                // processData: false,
                // contentType: false,
                type: 'GET',
                success: (data) => {
                    console.log('接收到信息', data)
                    alert(data);
                    //   loadFiles()
                    res( data )
                },
                error: (xhr, ajaxOptions, thrownError) => {
                    console.error('error', xhr, ajaxOptions, thrownError)
                    rej( thrownError )
                },
                complete : (XHR, TS) => {
                    this._parent.ind.show = false
                }
            });
        })  // promiese
    }

    _checkName(o) {
        const arr = o.querySelectorAll('input')

        let obj = {}
        for (let i in arr) {
            const v = arr[i]
            if (!v) continue
            console.log('ss', i, v.value)
            if (!v.value) continue
            obj[v.name] = v.value
        }
        // debugger
        return obj
    }
}